define('controllers/homepage', function (require, exports, module) {
	"use strict";

	var fnGlobalUrl = require[require.toUrl ? 'toUrl' : 'resolve'];
	var $window = $(window),
		$document = $(document);
		var m_Swiper = require('swiper2');
		var m_superslide = require('jquery.superslide')

	/* ************************************************************ */
	var m_Homepage = { /* 定义一个首页对象 */
		createNew: function () {
			if(!(window.basePage) || typeof(window.basePage.createNew) !=='function'){
				window.basePage={};
				window.basePage.createNew=function(){
					return {};
				}
			}
			var $internal = window.basePage.createNew();
			/* code here for example */
			$internal.Banner = null;

			$internal.init = function () { /* 页面类的初始化， 向$internal上绑定功能对象， 如下绑定 Banner 对象 */
				/*code here 如下： */
				this.Banner = new $Banner();
				this.News = new $News();
				this.NavIng = new $NavIng();
				this.Ranking = new $Ranking();
				this.HotComment = new $HotComment();
			};
			
			/*===============首页焦点轮播广告图===============*/
			var $Banner = new Class({
				initialize: function () {
					this._init();
				}
			});
			$Banner.extend({
				_init: function () {
					this.isAppear = false;
					this.mySwiper = null;
					this.myTimers = undefined;
					this._initDom();
				},
				_initDom: function () {
				},
				appear: function () {
					var mySwiper = new m_Swiper('.banner-container',{
						pagination: '.banner-pagination',
						paginationClickable: true,
						loop:true,
						autoplay: 5000,
						autoplayDisableOnInteraction : false
					})
					$('.arrow-left').on('click', function(e){
						e.preventDefault()
						mySwiper.swipePrev()
					})
					$('.arrow-right').on('click', function(e){
						e.preventDefault()
						mySwiper.swipeNext()
					})
				},
			});
			
			/*===============首页曝光台===============*/
			var $News = new Class({
				initialize: function () {
					this._init();
				}
			});
			$News.extend({
				_init: function () {
					this.isAppear = false;
					this.mySwiper = null;
					this.myTimers = undefined;
					this._initDom();
				},
				_initDom: function () {
					var _this = this;
					_this.msgNode = $('.J_msg_scroll');
					_this.newsNode = $('.J_news_scroll');
				},
				appear: function () {
					var _this = this;
					//头部消息向上滚动
					_this.msgNode.slide({
						mainCell:".msg-txtscroll-bd ul",
						autoPlay:true,
						effect:"top",
						vis:1,
					});
					//焦点新闻轮播
					_this.newsNode.slide({
						titCell:".hot-new-hd li",
						mainCell:".hot-new-bd ul",
						autoPlay:true,
						effect:"left"
					});
				},
			});

			/*===========导航进场============*/
			var $NavIng = new Class({
				initialize: function () {
					this._init();
				}
			});
			$NavIng.extend({
				_init: function () {
					this.isAppear = false;
					this.mySwiper = null;
					this.myTimers = undefined;
					this._initDom();
				},
				_initDom: function () {
					var _this = this;
				},
				appear: function () {
					var _this = this;
					_this.theDom();
				},
				theDom: function(){
					// $('#J_news-sect').find('.hp-nav-item').each(function(index, el){
					// 	var _theRandom=parseInt(700*Math.random()+800);
					// 	$(this).slideDown(_theRandom);
					// });
					$('#J_news-sect').addClass('animation');
					$('#J_news-sect').find('.hp-nav-item').hoverIntent({
						over: function(){
							$(this).addClass('hover');
						},
						out: function(){
							$(this).removeClass('hover');
							$(this).parents('.hp-news-sect').removeClass('animation').addClass('show');
						}
					});
				}
			});

			/*===========学校排行============*/
			var $Ranking = new Class({
				initialize: function () {
					this._init();
				}
			});
			$Ranking.extend({
				_init: function () {
					this.isAppear = false;
					this.mySwiper = null;
					this.myTimers = undefined;
					this._initDom();
					this.backups = [];
				},
				_initDom: function () {
					var _this = this;
					_this.nav = $('.J_rankingNav');
					_this.list = $('.J_rankingList');
				},
				appear: function () {
					var _this = this;

					var firstUrl = $('.J_rankingNav .s-tabs-item:eq(0)').attr('dataUrl');
					_this.getRanking(firstUrl,'.J_rankingNav .s-tabs-item:eq(0)');

					_this.nav.on('click','.s-tabs-item',function(){
						var _the = this,
								_theUrl = $(_the).attr('dataUrl');
						_this.getRanking(_theUrl,_the);
					});
				},
				foundRanking:function(data,name){
					var _this = this,
							newHtml = $('<div></div>'),
							_theDom = $('.J_rankingDom').html();
					for(var i=0;i<data.list.length;i++){
						var newItem = $('<article class="rank-item"></article>'),
								_theNum = i+1;
						newItem.html(_theDom);
						newItem.addClass('item'+i);
						newItem.find('.number-icon').text('no.'+_theNum).css('background-image','url(../../images/index/rank'+i+'.png)');
						newItem.find('.frac-txt em').text(data.list[i].fraction);
						newItem.find('.school-title a').text(data.list[i].title).attr('href',data.list[i].url);
						newItem.find('.school-add').text(data.list[i].address);
						newItem.find('.score-btn').attr('href',data.list[i].fractionUrl);
						newHtml.append(newItem);
					}
					var newNum = _this.backups.length||0;
					_this.backups[newNum] = {};
					_this.backups[newNum].name = name;
					_this.backups[newNum].html = newHtml;
					return newHtml;
				},
				getRanking: function(url,nav){
					var _this = this,
							flag = 0,
							newHtml = '',
							name = $(nav).find('.tab-c-tit').text();
					if(!flag){
						var jud=1;
						layer.load(1,{shade:[0.1,'#000']});
						if(_this.backups&&_this.backups.length>0){
							for(var i=0;i<_this.backups.length;i++){
								if(_this.backups[i].name = name){
									newHtml = _this.backups[i].html;
									_this.nav.find('.s-tabs-item').removeClass('active');
									$(nav).addClass('active');
									_this.list.html(newHtml.html());
								}
							}
						}
						if(!jud){
							_this.list.html(newHtml);
						}else{
							$.ajax({
								url: url,
								type: 'GET'
							})
							.done(function(res){
								if(!res.code){res=eval(res)};
								if(res.code==200&&res.data&&res.data.list&&res.data.list.length>0){
									var list = res.data;
									newHtml = _this.foundRanking(list,name);
									_this.nav.find('.s-tabs-item').removeClass('active');
									$(nav).addClass('active');
									_this.list.html(newHtml.html());
								}else if (res.code!=200){
									_this.list.html('<div class="noHas">'+ res.msg +'</div>');
								}else{
									_this.list.html('<div class="noHas">暂无数据！</div>');
								}
							})
							.fail(function() {
								_this.list.html('<div class="noHas">网络错误！</div>')
							})
							.always(function() {
								flag = 0;
								layer.closeAll('loading');

							});
						}
					}else{
						layer.alert('数据加载中，请稍后！');
					}
				}
			});

			/*===========热门点评============*/
			var $HotComment = new Class({
				initialize: function () {
					this._init();
				}
			});
			$HotComment.extend({
				_init: function () {
					this.isAppear = false;
					this.mySwiper = null;
					this.myTimers = undefined;
					this._initDom();
					this.backups = [];
				},
				_initDom: function () {
					var _this = this;
					_this.nav = $('.J_hotcomNav');
					_this.list = $('.J_hotcomList');
				},
				appear: function () {
					var _this = this;
					var firstUrl = $('.J_hotcomNav .review-tab:eq(0)').attr('dataUrl');
					_this.getHotcom(firstUrl,'.J_hotcomNav .review-tab:eq(0)');

					$('.J_hotcomNav').on('click','.review-tab',function(){
						var _the = this,
								_theUrl = $(_the).attr('dataUrl');
						_this.getHotcom(_theUrl,_the);
					});

					$('body').on('mouseenter mouseleave','.review-info',function(event){
						var _the = $(this),
						    top = parseInt(_the.css('top'));
						if(event.type == 'mouseenter'){
							top = top - 2;
							_the.css({'top':top+'px','box-shadow':'0 2px 18px rgba(77,92,124,0.4)'});
						}else if (event.type == 'mouseleave') {
							top = top + 2;
							_the.css({'top':top+'px','box-shadow':''});
						}
					});
				},
				foundHotcom: function(data,name){
					var _this = this,
							newHtml = $('<div></div>'),
							_theDom = $('.J_hotcomDom').html();
					for(var i=0;i<data.list.length;i++){
						var newItem = $('<article class="review-info"></article>'),
								_theNum = i+1;
						newItem.html(_theDom);
						if(data.list[i].newType==1){
							newItem.find('.info-tips').after('<i class="review-ico">new!</i>');
						}
						var rText = jQuery('<div></div>');
						rText.html(data.list[i].info);
						newItem.find('.review-title .review-link').text(data.list[i].title).attr('href',data.list[i].url);
						newItem.find('.review-desc p').append(rText.text());
						newItem.find('.review-source em').text(data.list[i].user);
						newItem.find('.review-source a').text(data.list[i].address).attr('href',data.list[i].schoolUrl);
						newHtml.append(newItem);
					}
					var newNum = _this.backups.length||0;
					_this.backups[newNum] = {};
					_this.backups[newNum].name = name;
					_this.backups[newNum].html = newHtml;
					return newHtml;
				},
				getHotcom: function(url,nav){
					var _this = this,
							flag = 0,
							newHtml = '',
							name = $(nav).find('.tab-c-tit').text();
					if(!flag){
						var jud=1;
						layer.load(1,{shade:[0.1,'#000']});
						if(_this.backups&&_this.backups.length>0){
							for(var i=0;i<_this.backups.length;i++){
								if(_this.backups[i].name = name){
									newHtml = _this.backups[i].html;
									_this.nav.find('.review-tab').removeClass('active');
									$(nav).addClass('active');
									_this.list.html(newHtml.html());
									_this.list.find('.review-desc p').each(function(){
										var _the = jQuery(this),
										    _theHeight = parseInt(_the.height());
										if(_theHeight>260){
											_the.parents('.review-desc').addClass('shade')
										}
									});
									_this.waterfall();
								}
							}
						}
						if(!jud){
							_this.list.html(newHtml);
							_this.list.find('.review-desc p').each(function(){
								var _the = jQuery(this),
								    _theHeight = parseInt(_the.height());
								if(_theHeight>260){
									_the.parents('.review-desc').addClass('shade')
								}
							});
							_this.waterfall();
						}else{
							$.ajax({
								url: url,
								type: 'GET'
							})
							.done(function(res){
								if(!res.code){res=eval(res)};
								_this.nav.find('.review-tab').removeClass('active');
								$(nav).addClass('active');
								if(res.code==200&&res.data&&res.data.list&&res.data.list.length>0){
									var list = res.data;
									newHtml = _this.foundHotcom(list,name);
									_this.list.html(newHtml.html());
									_this.list.find('.review-desc p').each(function(){
										var _the = jQuery(this),
										    _theHeight = parseInt(_the.height());
										if(_theHeight>260){
											_the.parents('.review-desc').addClass('shade')
										}
									});
									_this.waterfall();
								}else if (res.code!=200){
									_this.list.html('<div class="noHas">'+ res.msg +'</div>')
								}else{
									_this.list.html('<div class="noHas">暂无数据！</div>')
								}
							})
							.fail(function() {
								_this.list.html('<div class="noHas">网络错误！</div>')
							})
							.always(function() {
								flag = 0;
								layer.closeAll('loading');
							});
						}
					}else{
						layer.alert('数据加载中，请稍后！');
					}
				},
				waterfall: function(){
					var _this = this,
							newHeight = 0,
							newTop = 0,
							_theLi1 = 0,
							_theLi2 = 0,
							_theLi3 = 0;
					_this.list.find('.review-info').each(function(){
						var _theHeight = parseInt($(this).css('height')),
						    newLeft = 0;
						if(_theLi1<=_theLi2){
							newTop = _theLi1;
							newLeft = 0;
							_theLi1 = _theLi1 +_theHeight + 20;
						}else if(_theLi2<=_theLi3){
							newTop = _theLi2;
							newLeft = 300;
							_theLi2 = _theLi2 +_theHeight + 20;
						}else{
							newTop = _theLi3;
							newLeft = 600;
							_theLi3 = _theLi3 +_theHeight + 20;
						}
						if(_theLi1>=_theLi2){
							newHeight = _theLi1;
						}else if(_theLi2>=_theLi3){
							newHeight = _theLi2;
						}else{
							newHeight = _theLi3;
						}
						$(this).css({'top':newTop+'px','left':newLeft+'px'});
						$('.J_hotcomList').css('height',newHeight+'px');
					});
				}
			});

			return $internal; //返回对象
		}


	};
	exports.run = function () {
		var HOMEPAGE = m_Homepage.createNew();
		HOMEPAGE.init();
		$document.ready(function () {
			HOMEPAGE.Banner.appear();
			HOMEPAGE.News.appear();
			HOMEPAGE.NavIng.appear();
			HOMEPAGE.Ranking.appear();
			HOMEPAGE.HotComment.appear();
		});


	};
});
